<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>商品编辑</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/layui.css" rel="stylesheet" />
	<link href="/node_modules/LobsterUIFrame/layuiadmin/style/admin.css" rel="stylesheet" />
	<link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/modules/layui-icon-extend/iconfont.css"
		rel="stylesheet" />
	<script src="/node_modules/LobsterUIFrame/layuiadmin/layui/layui.js"></script>>
</head>

<body>
	<div class="layui-fluid box">
		<form class="layui-form" lay-filter="formdata" id="formdata" name="formdata">
			<div class="layui-card">
				<div class="layui-card-body">

					<div class="layui-row">
						<div class="layui-col-xs12">
							<div class="layui-form-item">
								<label class="layui-form-label"><i style="color:red;">*&ensp; </i>商品名称</label>
								<div class="layui-input-block">
									<input type="text" class="layui-input" lay-verify="required" id="GoodsName"
										name="GoodsName" disabled/>
								</div>
							</div>
						</div>
					</div>

					<div class="layui-row">
						<div class="layui-col-xs12">
							<div class="layui-form-item">
								<label class="layui-form-label">规格</label>
								<div class="layui-input-block">
									<select name="SpecId" id="SpecId" lay-filter="SpecId"
										lay-verify="required">
									</select>
								</div>
							</div>
						</div>
					</div>

					<div class="layui-row">
						<div class="layui-col-xs12">
							<div class="layui-form-item">
								<label class="layui-form-label">规格说明</label>
								<div class="layui-input-block">
									<input type="text" class="layui-input" id="SpecItemName" name="SpecItemName" />
								</div>
							</div>
						</div>
					</div>

					<div class="layui-form-item layui-hide">
						<input type="button" lay-submit lay-filter="btnSubmit" id="btnSubmit" value="确认">
					</div>
				</div>
			</div>
			<div class="layui-form-item layui-hide">
				<input type="button" lay-submit lay-filter="LAY-app-front-submit" id="LAY-app-front-submit" value="保存">
				<input type="button" lay-cancel lay-filter="LAY-app-front-cancel" id="LAY-app-front-cancel" value="取消">
				<input type="reset" id="LAY-app-form-reset" value="重置">
			</div>

			<div class="layui-form-item layui-hide">
				<input type="text" id="GoodsId" name="GoodsId" value="0" />
				<input type="text" id="SpecItemId" name="SpecItemId" value="0" />
			</div>
		</form>
	</div>
</body>

</html>
<script>
	layui.config({
		base: '/node_modules/LobsterUIFrame/layuiadmin/' //静态资源所在路径
	}).extend({
		index: 'lib/index' //主入口模块
	});

	layui.define(['index', 'layer', 'form', 'element', 'table', 'upload', 'laytpl'], function () {
		var layer = layui.layer;
		var form = layui.form;
		var element = layui.element;
		var table = layui.table;
		var $ = layui.$;
		var admin = layui.admin;
		var setter = layui.setter;
		var upload = layui.upload;
		var laytpl = layui.laytpl;


		var controller = {
			data: {
				model: {},
				fun: null,
				mainsrc: '',
				piclist: [],
			},
			//初始化页面
			initpage: function () {
				var self = this;
				console.log(parent.modelData)
				self.data.model = parent.modelData;

				self.initselect();
				self.initevent();
			},
			getbaseurl: function (fun) {
				var url = "/lowcode/APP20200616102057595/shop/?view=layui&fun=" + fun;
				return url;
			},
			initselect: function () {
				var self = this;
				var url = self.getbaseurl("Mall.getspecdic");
				admin.req({
					type: 'get',
					url: url,
					done: function (obj) {
						console.log(obj)
						$.each(obj.data, function (index, item) {
							$("#SpecId").append(new Option(item.Name, item.Code))
						})
						layui.form.render("select")
						self.initData();
					}
				});
			},
			//初始化事件
			initevent: function () {
				var self = this;
				parent.getResult = function (fun) {
					self.data.fun = fun;
					$("#btnSubmit").click();
				}
				form.on('submit(btnSubmit)', function (data) {
					data.field.SpecName = $("#SpecId").find("option:selected").text();
					console.log(data.field)
					self.data.fun(data.field);
				});


			},

			//加载数据
			initData: function () {
				var self = this;
				if (self.data.model) {

					console.log(self.data.model)
					form.val("formdata", Object.assign({}, self.data.model));
					
				}
			},
		}

		/*
		* 入口
		*/
		controller.initpage();
	});

</script>